package com.panda.qqclient.services;

import com.panda.qqcommon.Message;
import com.panda.qqcommon.MessageType;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

public class MessageClientService {

    public void sendMessageToOne(String content,String senderId,String getterId) throws IOException {

        Message message = new Message();
        message.setMessageType(MessageType.MESSAGE_COMMON_MESSAGE);
        message.setContent(content);
        message.setSender(senderId);
        message.setGetter(getterId);
        message.setSendTime(new Date().toString());

        //发送给服务端
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(ManageClientConnectServerThread.getFromMap(senderId).getSocket().getOutputStream());
        objectOutputStream.writeObject(message);
    }

    public void sendMessageToAll(String content,String senderId) throws IOException {
        Message message = new Message();
        message.setMessageType(MessageType.MESSAGE_TO_ALL);
        message.setContent(content);
        message.setSender(senderId);
        message.setSendTime(new Date().toString());

        new ObjectOutputStream(ManageClientConnectServerThread.getFromMap(senderId).getSocket().getOutputStream()).writeObject(message);


    }

}
